//导入express
const express = require("express")
//创建服务器
const App = express()
//cors同源策略
const cors = require("cors")
//解决同源
App.use(cors())
//中间件 参数解析
App.use(express.urlencoded({ extended: false }))
App.use(express.json())
//设置跨域访问
App.all('*', function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
      res.header("Access-Control-Allow-Headers", "content-type");
      res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
      res.header("X-Powered-By", ' 3.2.1')
      res.header("Content-Type", "application/json;charset=utf-8");
      next();
})
//调用App.listen(端口号，启动成功后的回调函数)
App.listen(4000,()=>{
    console.log("服务器启动成功");
})

//请求 Login post
App.post("/login",(req,res)=>{
    res.send({
        code:0,
        msg:"ok",
        data:{
            uid:1000,
            token:"laihong;yujianni;shixinyunyeshiyihan"
        }
    })
})